﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.Extensions.Localization;

namespace 国际化和本地化.Controllers
{
    [Route("[controller]")]
    public class LocalizationController : Controller
    {

        private readonly IStringLocalizer<LocalizationController> _localizer;

        private readonly IHtmlLocalizer<LocalizationController> _htmlLocalizer;

        public LocalizationController(IStringLocalizer<LocalizationController> localizer,
            IHtmlLocalizer<LocalizationController> htmlLocalizer)
        {
            _localizer = localizer;
            _htmlLocalizer = htmlLocalizer;
        }

        [HttpGet]
        [Route("Index")]
        public IActionResult Index([FromServices]IWebHostEnvironment _env)
        {
            return View();
        }

        public string Get()
        {
            return _localizer["Message"];
        }

        [Route("html")]
        public IActionResult HtmlLocalizer(string name)
        {
            //IHtmlLocalizer,返回html的内容
            ViewData["html"] = _htmlLocalizer[$"<p>{name}</p>"];
            return View();
        }

    }
}